<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title><{:C('web_site_name')}>---广告管理</title>
    <link rel="stylesheet" type="text/css" href="<?php echo APP_TMPL_PATH ; ?>/static/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="<?php echo APP_TMPL_PATH ; ?>/static/css/main.css"/>

    <script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/jquery.js"></script>
    <script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/layer/lib.js"></script>
	<script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/layer/layer.min.js"></script>
</head>
<body>
<div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i>首页<span class="crumb-step">&gt;</span><span class="crumb-name">后台广告管理</span></div>
        </div>
        <div class="search-wrap">
            <div class="search-content">
                <form action="#" method="post">
                    <table class="search-tab">
                        <tr>
                          
                            <th width="70">广告位置:</th>
                            <td>
                                <select name="typeid"  id="typeid">
                                 <option>请选择</option>
                                <?php 
                                    if(isset($list) && $list){
                                        foreach ($list as $k => $v ){
                                    
                                ?>
                             <option value="<?php echo $v['id'] ; ?>" <?php if($typeid == $v['id']){echo "selected";}?>><?php echo $v['typename'] ; ?></option>
        <?php } }?>
    </select>
                            </td>
                            <th width="70">广告名字:</th>
                     <td>
                         
                         <input id="" class="common-text" type="text" value="" name="name" placeholder="广告名字">
                     </td>
                      <th width="70">广告类型:</th>
                                <td>
                             <select name="type">
                                <option value="all">请选择</option>
                                <option value="1">文字广告</option>
                                <option value="0">图片广告</option>  
                            </select>
                                </td>
                                <th width="70">状态:</th>
                                <td>
                             <select name="status">
                                <option value="all">请选择</option>
                                <option value="1">开启</option>
                                <option value="0">关闭</option>  
                            </select>
                                </td>
                            <td><input class="btn btn-primary btn2" name="sub" value="查询" type="button" onclick="search()"></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
        <div class="result-wrap">
            <form name="myform" id="myform" method="post">
                <div class="result-title">
                    <div class="result-list">
                        <a href="javascript:void(0)" onclick="add()"><i class="icon-font"></i>新增广告</a>
                    </div>
                </div>
                 <div class="list-page" id="page_string"> 2 条 1/1 页</div>
                <div class="result-content">
                    <table class="result-tab" width="100%" >
                        <tr>
                            <th>编号</th>
                            <th>广告位置</th>
                            <th>广告名称</th>
                            <th>广告类型</th>
                            <th>权重</th>
                            <th>图片</th>
                            <th>图片2</th>
                            <th>添加日期 </th>
                            <th>开始日期 </th>
                            <th>结束日期 </th>
                            <th>属性1 </th>
                            <th>属性2 </th>
                            <th>状态</th>
                        
                       
                            <th>操作</th>
                        </tr>
                      <tbody id="result_"></tbody>
                        
                    </table>  
                    <div class="list-page" id="page_string"> 2 条 1/1 页</div>
                </div>
            </form>
        </div>
</body>
</html>
<script>
var loadding_0  ;
var page = 1 ;
$(function () {
    common_request();
});
function common_request(){
    var url="<?php echo U("ad/index");?>&inajax=1";
    var data_ = {
        'page':page,
        'time':<?php echo time();?>,
        'action':'ajax_data' , 
        'typename':$("input[name='typename']").val() , 
        'status':$("select[name='status']").val(),
        'type':$("select[name='type']").val(),
        'name':$("input[name='name']").val() ,
        'typeid':$("select[name='typeid']").val()

    } ;
    //console.dir(data_);
    $.ajax({
    type: "POST",
    url: url ,
    data: data_,
    cache:false,
    dataType:"json",
    async:true,
    success: function(msg){
        var shtml = '' ;
        var list = msg.resultinfo.list;
        
        if(msg.resultcode!= 1 ){
            layer.msg(msg.resultinfo.errmsg);
            return false ;
        }else{
        
            for(var i in list){
                shtml+='<tr>';
                shtml+= '<td>'+list[i].id+'</td>' ;
                shtml+='<td>'+list[i]['typename']+'</td>';
                shtml+='<td>'+list[i]['name']+'</td>';
                shtml+='<td>'+list[i]['type']+'</td>';
                shtml+='<td>'+list[i]['weight']+'</td>';
                shtml+='<td>'+list[i]['pic']+'</td>';
                shtml+='<td>'+list[i]['pic2']+'</td>';
                shtml+='<td>'+list[i]['addtime']+'</td>';
                shtml+='<td>'+list[i]['begin_date']+'</td>';
                shtml+='<td>'+list[i]['end_date']+'</td>';
                shtml+='<td>'+list[i]['attr_1']+'</td>';
                shtml+='<td>'+list[i]['attr_2']+'</td>';
                shtml+='<td>'+list[i]['status']+'</td>';
                shtml+='<td> <a href="javascript:void(0)" onclick="edit('+list[i].id+',this)" class="tablelink">修改</a>&nbsp;&nbsp;<a href="javascript:void(0)" onclick="del('+list[i].id+',this)" class="tablelink">删除</a></td>';
                shtml+='</tr>';
            }
            $("#result_").html(shtml);
            $(".list-page").html(msg.resultinfo.obj);
        }
        layer.close(loadding_0);
    },
    beforeSend:function(){
         loadding_0 = layer.load('数据正在加载中。。。。。。'); 
    },
    error:function(){
        layer.msg('服务器繁忙请稍后');
        return false ;
    }
    });
}
function ajax_data(p){
    page = p  ; 
    common_request();
}
function search(){
    page = 1 ;
    common_request();
}
var _add = '' ;
//添加广告
function add(){
    _add = $.layer({
        type: 2,
        shadeClose: true,
        title: "添加广告",
        closeBtn: [0, true],
        shade: [0.8, '#000'],
        border: [1],
        offset: ['20px',''],
        area: ['60%','660px'],
        fix:false,
        iframe: {src: "<?php echo U("ad/add");?>&showpage=1"}
    }); 
}
var _edit = '' ;

function edit(id , o ){
    _edit = $.layer({
        type: 2,
        shadeClose: true,
        title: "修改广告类型",
        closeBtn: [0, true],
        shade: [0.8, '#000'],
        border: [1],
        offset: ['20px',''],
        area: ['60%','600px'],
        fix:false,
        iframe: {src: "<?php echo U("ad/edit");?>&showpage=1&id="+id}
    }); 
}

//删除广告
var _del = '' ;
function del(id , o ){
    $.layer({
        shade: [0.8, '#000'],
        area: ['240px','auto'],
        shift: 'left', //从左动画弹出
        dialog: {
            msg: '确定删除数据吗？此操作不可恢复!',
            btns: 2,                    
            type: 4,
            btn: ['确定','取消'],
            yes: function(){
                $.ajax({
                       type: "POST",
                       url: "<?php echo U('ad/del');?>" ,
                       data: {"id":id},
                       cache:false,
                       dataType:"json",
                       async:true,
                       success: function(msg){
                           if(msg.resultcode != 1){
                              layer.msg(msg.resultinfo.errmsg);
                             return false ; 
                            }else{
                                common_request();
                            }
                            layer.close(loadding_0);
                       },
                       beforeSend:function(){
                              var loadding_0 = layer.load('数据处理中....'); 
                       },
                       error:function(){
                               loadding_1 = layer.load('服务器繁忙请稍后等待。。。。。。'); 
                       }
                      
                    }); 
                //layer.msg('重要', 1, 1);
            }, no: function(){
                
            }
        }
    });
}
//关闭窗口
function close_add_div(){
    layer.close(_add);
}
//关闭窗口
function close_edit_div(){
    layer.close(_edit);
}
//编辑状态
function editStatus (id , status ){
    $.ajax({
    type: "POST",
    url: "<{:U('ad/edit')}>&action=doStatus" ,
    data: {id:id , status:status},
    cache:false,
    dataType:"json",
    async:true,
    success: function(msg){
        var shtml = '' ;
        var list = msg.resultinfo.list;
        
        if(msg.resultcode!= 1 ){
            layer.msg(msg.resultinfo.errmsg);
            return false ;
        }else{
            
        }
        layer.close(loadding_0);
    },
    beforeSend:function(){
         loadding_0 = layer.load('数据正在处理中。。。。。。'); 
    },
    error:function(){
        layer.msg('服务器繁忙请稍后');
        return false ;
    }
    });
}

</script> 

